
%%%%%%%%%%%%%%%%%%%%%%%
% est_sc_5_beta_serialcorrelation_sc.m


%cd /projects/programs/monarch/china/china_updated/data/
%load estimation_nobs_wrongorder.raw;
%indN=length(estimation_nobs_wrongorder);

industry=0;
beta_full=zeros(1,4);
importers=0;
exporters=0;

for w=1:49

folder=sprintf('../china/estimation/serial_correlation/raw/sc/raw%d',w)


cd (folder)

load imp.raw;
load data2_q.mat
load beta_newq.mat;

M=length(imp);

beta_full=[beta_full; beta_p_sol beta_x_sol beta_c_sol xi_tilde_sol];
importers=[importers; M];
exporters=[exporters; X];
end

beta_full=beta_full(2:end,:);
importers=importers(2:end,:);
exporters=exporters(2:end,:);


summary=[importers exporters];
beta_full

% Some Monte Carlo runs did not produce estimates
beta_full=[beta_full(1:15,:) ; 
beta_full(17:21,:); 
beta_full(23:26,:) ;
beta_full(28:35,:) ;
beta_full(37:39,:) ;
beta_full(41:end,:) ];


b1=mean(beta_full)
b2=median(beta_full)
b3=sqrt(var(beta_full))

beta_summary=[b1; b2; b3];
cd ../china/estimation/serial_correlation
%save('beta_summary','beta_summary')
%dlmwrite('beta_summary.txt',beta_summary)